package game.controller;
import game.controller.*;
import game.object.*;
import javafx.util.Math.*;

var playerList:Player[] = PlayerManager.newPlayerList(["Player1", "Player2", "Player3"]);
var cardList  :Card[]   = CardManager.newCardList();

var cardsToDistribute:Card[] = cardList;

public class GameController {
	
};

/**********************************************************
	Function List
**********************************************************/

// randomly distribute cards
public function distributeCards()
{
	var playerIndex    = 0;    
    while (cardsToDistribute.size() > 0)
    {
        var rndCardIndex = round(cardsToDistribute.size()*random());
        if (rndCardIndex > cardsToDistribute.size()){ rndCardIndex--; }
        
        if (cardsToDistribute[rndCardIndex].label != "")
		{
			insert cardsToDistribute[rndCardIndex] into playerList[playerIndex].cardList;
			 
		}
		delete cardsToDistribute[rndCardIndex];  
		
		playerIndex++;
		if (playerIndex >= playerList.size()){ playerIndex = 0; }
    }
	/*    
    // print cards of all players
    for (i in [0..playerList.size()-1])
    {
        println("{playerList[i].myName}\n----------");
        for (j in [0..playerList[i].cardList.size()-1])
        {
            println(" > {playerList[i].cardList[j].label}");
        }
        println("*****************");
    }*/
}